from django.contrib import admin
from .models import CourseDiretion,CourseCategory,Course,Teacher,CourseChapter,CourseLesson
# Register your models here.
class CourseDiretionModelAdmin(admin.ModelAdmin):
    """学习方向的模型管理器"""
    list_display = ["id","name","recomment_home_hot","recomment_home_top"]

admin.site.register(CourseDiretion, CourseDiretionModelAdmin)

class CourseCategoryModelAdmin(admin.ModelAdmin):
    """课程分类的模型管理器"""
    list_display = ["id","name","diretion"]

admin.site.register(CourseCategory, CourseCategoryModelAdmin)


class CourseModelAdmin(admin.ModelAdmin):
    """课程信息的模型管理器"""
    list_display = ["id","name","course_type","level","pub_date","students","lessons","price"]

admin.site.register(Course, CourseModelAdmin)


class TeacherModelAdmin(admin.ModelAdmin):
    """讲师信息的模型管理器"""
    list_display = ["id","name","title","role","signature"]

admin.site.register(Teacher, TeacherModelAdmin)

class CourseChapterModelAdmin(admin.ModelAdmin):
    """课程章节的模型管理器"""
    list_display = ["id","course","orders","name", "pub_date",]
admin.site.register(CourseChapter, CourseChapterModelAdmin)


class CourseLessonModelAdmin(admin.ModelAdmin):
    """课程课时的模型管理器"""
    list_display = ["id","course","chapter_name","name","orders"]

    # admin自定义字段
    def chapter_name(self, obj):  # obj本次要显示的模型对象
        return f"第{obj.chapter.orders}章 {obj.chapter.name}"

    # admin的排序设置,排序时因为admin声明的字段本质上不属于模型的，我们要排序的参考数据必须来源于数据库中的，所以值一般就是模型的字段
    chapter_name.admin_order_field = "chapter"
    chapter_name.short_description = "章节信息"

admin.site.register(CourseLesson, CourseLessonModelAdmin)



